const SpiderBaseClass = require('./SpiderBaseClass');

const listSize = 120;//列表页面有多少个主播信息
class SpiderQuanMin extends SpiderBaseClass {

  static firstListPage() {
    return 0;
  }

  /**
   * 获取其它页码的列表页面
   * @param page
   */
  static async getListPage(page) {
    const res = await SpiderQuanMin.get(SpiderQuanMin.listPageUrl(page),
      {
        dataType: 'json',
        headers: SpiderQuanMin.headers('https://www.quanmin.tv/'),
      });

    const list = res.data.data.map(room => {
      return {
        anchor: {
          room: room.no,
          name: room.nick,
          gender: 0,
          avatar: room.avatar,
        },
        type: room.category_name,
        data: {
          num_watch: SpiderQuanMin.toNumber(room.view),
          num_live: 0,
          num_gift: 0,
          num_follower: SpiderQuanMin.toNumber(room.follow),
        },
      };
    });
    return {
      list,
      page,
      nextPage: page + 1,
      hasNextPage: list.length >= listSize,
    };
  }

  /**
   * 获取直播间信息
   * @param room
   */
  static getRoom(room) {
  }

  /**
   * 生成列表页面的网址
   * @param page
   * @return string
   */
  static listPageUrl(page) {
    return `https://xapi.quanmin.tv/x/room/index/list?client=1&p=${page}&toid=0&cv=default_4.3.50&ua=hammerhead&conn=WIFI&osversion=android_23&cid=6`;
  }

  /**
   * 生成直播间信息的网址
   * @param id
   * @return string
   */
  static roomUrl(id) {
  }

}

module.exports = SpiderQuanMin;